package com.jimmy.medical.entity;

import com.jimmy.medical.enums.OrderTypeEnum;
import com.jimmy.medical.enums.YnEnum;
import org.apache.commons.lang.math.NumberUtils;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * @Desc: 订单针对就诊记录、体检记录两种类型的执行记录

 * @author jimmy

 * @date 2018-04-22
 */
@Entity
@Table(name = "order_execution_record")
public class OrderExecutionRecord extends AbstractEntity {
	
	/**服务项目/体检内容，文字描述*/
	@Column(name = "service_item")
	private String serviceItem;
	
	/**症状/体检报告描述/服务记录*/
	@Column(name = "check_info")
	private String checkInfo;
	
	/**异常检查结果*/
	@Column(name = "exception_result")
	private String exceptionResult;
	
	/**就诊诊断*/
	@Column(name = "diagnose_result")
	private String diagnoseResult;
	
	/**处方*/
	@Column(name = "paper")
	private String paper;
	
	/**复诊意见*/
	@Column(name = "recheck_advice")
	private String recheckAdvice;
	
	/**注意事项*/
	@Column(name = "note")
	private String note;
	
	/**客户反馈情况收集*/
	@Column(name = "customer_back_collection")
	private String customerBackCollection;
	
	/**备注*/
	@Column(name = "info")
	private String info;
	
	/**检查记录：有/无 1/0*/
	@Column(name = "has_check_record")
	private Integer hasCheckRecord;
	
	/**检查报告信息，添加评估报告时使用*/
	@Column(name = "check_report")
	private String checkReport;
	
	/** 对应的订单*/
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "order_id")
    @NotFound(action = NotFoundAction.IGNORE)
    private Order order;
	
    /** 操作人*/
	@Column(name = "create_user")
	private String createUser;
	
	/**操作时间*/
	@Column(name = "create_time", length = 20)
	private String createTime;
	
	/** 更新人*/
	@Column(name = "update_user")
	private String updateUser;
	
	/**更新时间*/
	@Column(name = "update_time", length = 20)
	private String updateTime;

	/**标记就诊报告(异常检查结果)是否已读0/1，默认未读*/
	@Column(name = "is_read", length = 2)
	private Integer isRead = YnEnum.NO.getKey();
	
	/**体检医院名称，如果体检报告非言康，则保存手动输入的体检医院名称*/
	@Column(name = "physical_hospital_name")
	private String physicalHospitalName;

	
	/** 对应的会员,为了与老系统兼容,老系统导入的数据没有对应的订单,只能统一挂在会员下*/
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "member_id")
    @NotFound(action = NotFoundAction.IGNORE)
	private Member member;
	
	/**检查时间,兼顾老系统,新系统的订单时间在订单中,老系统导入的数据无法关联订单*/
	@Column(name = "check_time", length = 50)
	private String checkTime;
	/**检查类型,兼顾老系统 1是就诊2是体检*/
	@Column(name = "check_type", length = 10)
	private String checkType;
	/** 部门*/
	@Column(name="department")
	private String department;
	/**医生*/
	@Column(name="doctor")
	private String doctor ;
	
	/**陪诊人*/
	@Column(name = "accompany_examine_person", length = 32)
	private String accompanyExaminePerson;

	/**
	 * 附属图片(逗号分隔，前后无逗号，如果要like查询，自己在前面和后面加上逗号“‘，’||‘”)
	 */
	@Column(name = "files_list", length = 128)
	private String filesList;

	@Transient
	private Long flowOrderId;

	@Transient
	private Long userID;
	
	public String getFilesList() {
		return filesList;
	}

	public void setFilesList(String filesList) {
		this.filesList = filesList;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getDoctor() {
		return doctor;
	}

	public void setDoctor(String doctor) {
		this.doctor = doctor;
	}

	/**
	 * 获取html格式的记录汇总
	 * @return
	 */
	public String getSummaryDescHtml() {
		StringBuffer sb = new StringBuffer();
		int orderType = -1;
		if (order != null) {
			orderType = NumberUtils.toInt(order.getOrderType(), -1);
		}
		if (orderType == OrderTypeEnum.PHYSICAL_CHECK.getKey()) {	//体检
			sb.append("<b>体检内容</b>：");
			sb.append(serviceItem).append("<br/>");
			sb.append("<b>体检报告概述</b>：");
			sb.append(checkInfo).append("<br/>");
		} else {
			sb.append("<b>检查项目</b>：");
			sb.append(serviceItem).append("<br/>");
			sb.append("<b>症状</b>：");
			sb.append(checkInfo).append("<br/>");
		}
		
		if (orderType == OrderTypeEnum.DIAGNOSE.getKey()) {	//就诊
			sb.append("<b>异常检查结果</b>：");  //bob 20161122 因为这个格式化了，在这里显示不方便
			sb.append(exceptionResult).append("<br/>");
			sb.append("<b>就诊诊断</b>：");
			sb.append(diagnoseResult).append("<br/>");
			sb.append("<b>处方</b>：");
			sb.append(paper).append("<br/>");
			sb.append("<b>复诊意见</b>：");
			sb.append(recheckAdvice).append("<br/>");
			sb.append("<b>注意事项</b>：");
			sb.append(note).append("<br/>");
		}
		
		sb.append("<b>客户反馈情况收集</b>：");
		sb.append(customerBackCollection).append("<br/>");
		sb.append("<b>备注</b>：");
		sb.append(info).append("<br/>");
		return sb.toString();
	}
	
	/**
	 * 获取html格式的记录汇总的文本内容
	 * @return
	 */
	public String getSummaryContent() {
		StringBuffer sb = new StringBuffer();
		int orderType = -1;
		if (order != null) {
			orderType = NumberUtils.toInt(order.getOrderType(), -1);
		}
		if (orderType == OrderTypeEnum.PHYSICAL_CHECK.getKey()) {	//体检
			sb.append("<p>体检内容：");
			sb.append(serviceItem).append("</p>");
			sb.append("<p>体检报告概述：");
			sb.append(checkInfo).append("</p>");
		} else {
			sb.append("<p>检查项目：");
			sb.append(serviceItem).append("</p>");
			sb.append("<p>症状：");
			sb.append(checkInfo).append("</p>");
		}
		
		if (orderType == OrderTypeEnum.DIAGNOSE.getKey()) {	//就诊
			sb.append("<p>异常检查结果：");
			sb.append(exceptionResult).append("</p>");
			sb.append("<p>就诊诊断：");
			sb.append(diagnoseResult).append("</p>");
			sb.append("<p>处方：");
			sb.append(paper).append("</p>");
			sb.append("<p>复诊意见：");
			sb.append(recheckAdvice).append("</p>");
			sb.append("<p>注意事项：");
			sb.append(note).append("</p>");
		}
		
		sb.append("客户反馈情况收集：");
		sb.append(customerBackCollection).append("\n");
		sb.append("备注：");
		sb.append(info).append("\n");
		return sb.toString();
	}
	
	public String getServiceItem() {
		return serviceItem;
	}

	public void setServiceItem(String serviceItem) {
		this.serviceItem = serviceItem;
	}

	public String getCheckInfo() {
		return checkInfo;
	}

	public void setCheckInfo(String checkInfo) {
		this.checkInfo = checkInfo;
	}

	public String getExceptionResult() {
		return exceptionResult;
	}

	public void setExceptionResult(String exceptionResult) {
		this.exceptionResult = exceptionResult;
	}

	public String getDiagnoseResult() {
		return diagnoseResult;
	}

	public void setDiagnoseResult(String diagnoseResult) {
		this.diagnoseResult = diagnoseResult;
	}

	public String getPaper() {
		return paper;
	}

	public void setPaper(String paper) {
		this.paper = paper;
	}

	public String getRecheckAdvice() {
		return recheckAdvice;
	}

	public void setRecheckAdvice(String recheckAdvice) {
		this.recheckAdvice = recheckAdvice;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public String getCustomerBackCollection() {
		return customerBackCollection;
	}

	public void setCustomerBackCollection(String customerBackCollection) {
		this.customerBackCollection = customerBackCollection;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public Integer getHasCheckRecord() {
		return hasCheckRecord;
	}

	public void setHasCheckRecord(Integer hasCheckRecord) {
		this.hasCheckRecord = hasCheckRecord;
	}

	public String getCheckReport() {
		return checkReport;
	}

	public void setCheckReport(String checkReport) {
		this.checkReport = checkReport;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public Integer getIsRead() {
		return isRead;
	}

	public void setIsRead(Integer isRead) {
		this.isRead = isRead;
	}

	public String getPhysicalHospitalName() {
		return physicalHospitalName;
	}

	public void setPhysicalHospitalName(String physicalHospitalName) {
		this.physicalHospitalName = physicalHospitalName;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public String getCheckTime() {
		return checkTime;
	}

	public void setCheckTime(String checkTime) {
		this.checkTime = checkTime;
	}

	public String getCheckType() {
		return checkType;
	}

	public void setCheckType(String checkType) {
		this.checkType = checkType;
	}
	
	public String getAccompanyExaminePerson() {
		return accompanyExaminePerson;
	}

	public void setAccompanyExaminePerson(String accompanyExaminePerson) {
		this.accompanyExaminePerson = accompanyExaminePerson;
	}

	public String getCheckTimeNormal() {
		if(order != null) {
			return order.getOrderDate();
		} else {
			return checkTime;
		}
	}
	
	public String getCheckContent() {
		if(order != null) {
			if(order.getOrderType().equals(String.valueOf(OrderTypeEnum.DIAGNOSE.getKey()))) {
				return exceptionResult;
			} else if(order.getOrderType().equals(String.valueOf(OrderTypeEnum.PHYSICAL_CHECK.getKey()))) {
				return checkInfo;
			}
		} else {
			if("检查".equals(checkType)) {
				return exceptionResult;
			} else {
				return checkInfo;
			}
		}
		
		return "";
	}

	public Long getFlowOrderId() {
		return flowOrderId;
	}

	public void setFlowOrderId(Long flowOrderId) {
		this.flowOrderId = flowOrderId;
	}

	public Long getUserID() {
		return userID;
	}

	public void setUserID(Long userID) {
		this.userID = userID;
	}
}
